package com.example.twoapplication

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity

class MyActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        val linearLayout = LinearLayout(this)
        linearLayout.orientation = LinearLayout.VERTICAL

        val imageView = ImageView(this).apply {
            layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
            setPadding(16,8,16,8)

            setImageResource(R.drawable.flag)
        }

        val textView = TextView(this).apply {
            layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
            textSize = 30F
            text = getString(R.string.textView)
        }
        textView.setPadding(16,50,16,16)

        val button = Button(this).apply {
            layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
            text = getString(R.string.button)
            setPadding(16,8,16,8)
        }

        linearLayout.addView(imageView)
        linearLayout.addView(textView)
        linearLayout.addView(button)

        setContentView(linearLayout)





//        setContentView(R.layout.onelayout) //连接页面
//        val button = findViewById<Button>(R.id.button)
//        val textView = findViewById<TextView>(R.id.textView)

//        val linearLayout = LinearLayout( this)
//        linearLayout.orientation = LinearLayout.VERTICAL
//
//        val textView = TextView(this)
//        textView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
//        textView.textSize = 30F
//        textView.text = getString(R.string.textView)
//        linearLayout.addView(textView)
//
//        val button = Button(this)
//        textView.width = ViewGroup.LayoutParams.MATCH_PARENT
//        textView.height = ViewGroup.LayoutParams.WRAP_CONTENT
//        textView.text = getString(R.string.button)
//        linearLayout.addView(button)
//
//        setContentView(linearLayout)


        button.setOnClickListener { //点击按钮
            textView.text = resources.getString(R.string.clicked)
        }
    }
}